package util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.SimpleTimeZone;

/**
 * Created by Administrator on 2018/11/23.
 */
public class DateUtil {
        private static SimpleDateFormat sdf;
    /**
     * 方法概述： 把时间戳改成String格式
     *
     * @param date
     * @param pattern
     * @return
     */
        public static String stringDate(Date date,String pattern){
                sdf=new SimpleDateFormat(pattern);
                return sdf.format(date);
        }

    /**
     * 方法概述：把String 日期格式改为date格式
     * @param date
     * @param pattern
     * @return
     * @throws ParseException
     */
        public static Date dateString(String date,String pattern) throws ParseException {
            sdf=new SimpleDateFormat(pattern);
            return sdf.parse(date);
        }

    /**
     * 方法概述：把字符串日期格式转为时间戳
     * @param date_str
     * @param format
     * @return
     */
    public static String TimeStamp(String date_str,String format){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            return String.valueOf(sdf.parse(date_str).getTime()/1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

}
